package customerEnter.Frame.Login;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import customerEnter.tool.UserInfoCounts;

public class LoginInvocationHandler implements InvocationHandler {
	private Object	target;
	ServletRequest	request;
	ServletResponse	Response;

	public LoginInvocationHandler(Object target, ServletRequest request, ServletResponse response) {
		super();
		this.target = target;
		this.request = request;
		this.Response = response;
	}

	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Object result = null;

		if (UserInfoCounts.getCustomersId() <= 0) {
			request.getRequestDispatcher("Login.jsp").forward(request, Response);
		} else {
			result = method.invoke(target, args);
		}
		return result;
	}

	public Object getProxy() {
		return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
				target.getClass().getInterfaces(), this);
	}
}
